package com.weilive.pay;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.weilive.core.facade.Bootstrap;
import com.weilive.core.netty.spring.NettySpringServer;
import com.weilive.core.utils.FileUtils;

public class Main {
	private static final Logger logger = LoggerFactory.getLogger(Main.class);

	public static void main(String[] args) throws Exception {
		/* 获取workPath */
		String springXML = "application-context.xml";
		// 加载服务器配置
		ServerContext.loadData(FileUtils.getResourceDir(springXML));

		/* 加载Spring配置文件 */
		ApplicationContext context = new ClassPathXmlApplicationContext("classpath*:/" + springXML);
		ServerContext.setContext(context);

		// 加载各个启动器
		for (Bootstrap bootstrap : context.getBeansOfType(Bootstrap.class).values()) {
			bootstrap.loadBySpring(context);
		}
		// 启动各个网络服务
		for (NettySpringServer springServer : context.getBeansOfType(NettySpringServer.class).values()) {
			springServer.getServer().start();
		}

		logger.warn("--------------Pay服务器启动成功--------------");

	}
}
